<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<!--
  Copyright © 2023 Petr Panteleyev <petr@panteleyev.org>
  SPDX-License-Identifier: BSD-2-Clause
  -->
<!--suppress SqlNoDataSourceInspection -->
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
                   xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
                   xmlns:pro="http://www.liquibase.org/xml/ns/pro"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.1.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd"
                   logicalFilePath="v23.9.1/changelog.xml">

    <changeSet id="v23.9.1-exchange-security" author="petr-panteleyev@yandex.ru">
        <sql>
            CREATE TABLE exchange_security (
                uuid                UUID            NOT NULL PRIMARY KEY,
                sec_id              VARCHAR         NOT NULL,
                name                VARCHAR         NOT NULL,
                short_name          VARCHAR         NOT NULL,
                isin                VARCHAR         NOT NULL,
                reg_number          VARCHAR         NOT NULL,
                face_value          DECIMAL(15, 6)  NOT NULL,
                issue_date          BIGINT          NOT NULL,
                mat_date            BIGINT,
                days_to_redemption  INT,
                group_type          VARCHAR         NOT NULL,
                group_name          VARCHAR         NOT NULL,
                type                VARCHAR         NOT NULL,
                type_name           VARCHAR         NOT NULL,
                market_value        DECIMAL(15, 6)  NOT NULL,
                coupon_value        DECIMAL(15, 6),
                coupon_percent      DECIMAL(15, 6),
                coupon_date         BIGINT,
                coupon_frequency    INT,
                accrued_interest    DECIMAL(15, 6),
                coupon_period       INT,
                created             BIGINT          NOT NULL,
                modified            BIGINT          NOT NULL,

                UNIQUE(sec_id)
            )
        </sql>
        <rollback>
            <sql>
                DROP TABLE exchange_security
            </sql>
        </rollback>
    </changeSet>

    <changeSet id="v23.9.1-account-security" author="petr-panteleyev@yandex.ru">
        <sql>
            ALTER TABLE account ADD COLUMN security_uuid UUID;

            ALTER TABLE account
                ADD CONSTRAINT account_security_uuid_fk FOREIGN KEY (security_uuid)
                REFERENCES exchange_security (uuid) ON DELETE RESTRICT ON UPDATE RESTRICT;
        </sql>
        <rollback>
            <sql>
                ALTER TABLE account DROP COLUMN security_uuid;
            </sql>
        </rollback>
    </changeSet>
</databaseChangeLog>
